package com.war.config;

import com.ejb.config.IApplicationConfig;
import com.ejb.metier.IConfigManager;
import javax.ejb.EJB;
import javax.faces.bean.ApplicationScoped;
import javax.faces.bean.ManagedBean;

/**
 *
 * @author Ambroise
 */
@ManagedBean(name="webSiteConfig")
@ApplicationScoped
public class WebSiteConfig{

	@EJB
	private IApplicationConfig applicationConfig;
    
    @EJB
    private IConfigManager configManagerBean;
	
	/**
	 * String defined the base url.
	 */
	private String baseUrl = "http://localhost:1080/ProjectJee-war/";
	
	/**
	 * String defined the path url for generate http links. Used for generate all links. (Absolute links)
	 * Info: For get the baseUrl with JSF: #{facesContext.externalContext.requestContextPath}
	 */
	private String facesUrl = baseUrl+"faces/";
	
	/**
	 * Resources path. Don't forgot to add "?ln=THEME" at the end of string for get in the good theme directory.
	 */
	private String resourcesUrl = facesUrl+"javax.faces.resource/";
    
    /*
     * Administration path.
     */
    private String administrationUrl = facesUrl+"administration/";
    
    /*
     * Template path.
     */
    private String templatesUrl = "./templates/";

    private int numberOfBooks;
    
    public String getTemplatesUrl() {
        return templatesUrl;
    }

    public String getFacesUrl() {
        return facesUrl;
    }

    public String getAdministrationUrl() {
        return administrationUrl;
    }

	public String getResourcesUrl() {
		return resourcesUrl;
	}

	public String getPathUrl() {
		return facesUrl;
	}

	public String getBaseUrl() {
		return baseUrl;
	}

    public int getNumberOfBooks() {
        numberOfBooks = configManagerBean.getNbBookDisplayed();
        return numberOfBooks;
    }

    public void setNumberOfBooks(int numberOfBooks) {
        configManagerBean.updateNbBooksDisplayed(numberOfBooks);
        this.numberOfBooks = numberOfBooks;
    }
	
    
       
	public String getEnvironment(){
		return this.applicationConfig.getEnvironment();
	}
	
	public String getLang(){
		return this.applicationConfig.getLang();
	}
	
	public void setLang(String lang){
		this.applicationConfig.setLang(lang);
	}
    
	public String getVersion(){
		return this.applicationConfig.getVersion();
	}
	
	
}
